package util;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;

/**
 * Classe utilitária do Hibernate com um método para recuperar a SessionFactory. 
 *
 * @author Lucas S bueno
 */
public class HibernateUtil {

   private static final SessionFactory sessionFactory;

   static {
      try {
        //Cria um objeto SessionFactory com a configuração padrão (hibernate.cfg.xml)
         sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
      } catch (Throwable ex) {         
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }
}
